package com.easy.controller;


import com.easy.bean.Reservation;
import com.easy.service.ReservationService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("reservation")
public class ReservationController {
    @Autowired
    ReservationService reservationService;

    @PostMapping
    public Result add(@RequestBody Reservation reservation) {
        Object obj = reservationService.add(reservation);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Reservation reservation) {
        Object obj = reservationService.edit(reservation);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable(name = "id") Integer id) {
        Object obj = reservationService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = reservationService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Reservation reservation) {
        Object obj = reservationService.all(reservation);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, Reservation reservation) {
        reservationService.page(page, reservation);
        return Result.success(page);
    }
}